package com.my.study.algorithm.newlink;

import java.util.Arrays;

/**
 * @author Carlos
 * @version 1.0.0
 * @date 2023/3/24 20:16
 */
public class NewLink {

    public static void main(String[] args) {
//        Scanner sc = new Scanner(System.in);
//        int n = sc.nextInt();
//        int[] fire = new int[n];
//        for (int i = 0; i < n; i++) {
//            fire[i] = sc.nextInt();
//        }
//        

        int[] fire = {1, 10, 20, 9};
        System.out.println(minSub(fire));
    }

    private static int minSub(int[] a) {
        int len = a.length;
        Arrays.sort(a);
        int minSub = Integer.MAX_VALUE;
        for (int i = 0; i < len - 1; i++) {
            minSub = Math.min(minSub, Math.abs(a[i] - a[i+1]));
        }
        
        return minSub;
    }


    private static int minSub1(int[] a) {
        int len = a.length;
        int tmp = a[0];
        int minSub = Integer.MAX_VALUE;
        for (int i = 1; i < len; i++) {
            tmp = Math.min(tmp, -a[i]);
            minSub = Math.min(minSub, tmp - a[i]);
        }

        return minSub;
    }
}
